<template>
  <el-select
    :value="value"
    :multiple="formItem.dataType === 5 ? true : false"
    clearable
    @input="handleChange"
    @change="changeValied(formItem)"
  >
    <el-option
      v-for="(item, index) in selectOptions"
      :key="index"
      :label="item"
      :value="item"/>
  </el-select>
</template>

<script>
export default {
  name: 'ValiSelect',
  model: {
    prop: 'value',
    event: 'change'
  },
  props: {
    value: {
      type: [String, Array], // 验证类型后续可以增加
      default: () => {
        return this.formItem.dataType === 5 ? this.value.split(',') : this.value
      }
    },
    formItem: {
      type: Object,
      default: () => ({})
    }
  },
  computed: {
    selectOptions: function() {
      return this.formItem.dataSource.split(',')
    }
  },
  methods: {
    handleChange(v) {
      this.$emit('change', v)
    },
    changeValied(item) {
      this.$emit('changeValied', item)
    }
  }
}
</script>

<style scoped lang="scss"></style>
